function initStore(stores) {
    const slice = Function.prototype.call.bind(Array.prototype.slice)
    var states = {},
        getters = {},
        mutations = {};

    var store,
        storeState = {};
    var  sotrekey=Object.keys(stores);

    sotrekey.forEach(name => {
        var  st=stores[name];
        states[name] = st.data;
        mutations[name] = (state, payload) => state[name] = payload;

        var getterfn = st.getters;
        //数据异步
        if (!st.async) {
            if (!getterfn) {
                //没有设置
                getters[name] = (state) => state[name]
            } else {
                getters[name] = () => {
                    var args = slice(arguments);
                    var state = args.shift();
                    return getterfn(state[name], args[0])
                }
            }
        } else {
            //异步promise
            var isObject = Object.prototype.toString.call(st.data) === '[object Object]',
                getinitVal = () => isObject ? {} : [],
                real = name + '_real',
                initVal = getinitVal(),
                commitCount = 0,
                lastCommitCount;
            //默认的mutatiosn，变成重置数据
            mutations[name] = (state) => {
                commitCount++
                state[real] = initVal = getinitVal();
            };
            states[real] = st.data;
            //实际的数据赋值
            mutations[real] = (state, payload) => {
                var kkey;
                if (kkey = payload.kkey) {
                    state[real][kkey] = payload.data;
                } else {
                    state[real] = payload.data;
                }
            }
            if (!st.gettersIsFn) {
                getters[name] = function () {
                    var args = slice(arguments);
                    var state = args.shift();
                    //未初始化，promise pending
                    if (state[real] === initVal && !storeState[name]) {
                        storeState[name] = st.async(args[0]);
                        storeState[name].then(data => {
                            //
                            store.commit(real, data);
                            storeState[name] = null;
                        })
                    }
                    return state[real];
                }
            } else {
                getters[name] = function () {
                    var state = slice(arguments)[0];

                    return function () {
                        var arg = slice(arguments)[0];
                        var hasArg = typeof arg !== undefined;
                        
                        //创建唯一键
                        var kkey = hasArg ? (JSON.stringify(arg) + name) : name;
                        //未初始化 还在初始值
                        if (state[real] === initVal || (hasArg && !state[real][kkey])) {
                            if (lastCommitCount !== commitCount) {
                                lastCommitCount = commitCount;
                                //取消上一个同步
                                storeState[kkey]&&storeState[kkey].cancel();
                                //检查是否有cancel
                                var asyncPromise = st.async(arg);
                                
                                var resolve,
                                    promise = new Promise(res => resolve = res);
                                asyncPromise.then(data => {
                                    if(!promise.isCancel){
                                        resolve(data)
                                    }
                                });
                                promise.cancel=()=>{
                                    asyncPromise.cancel&&asyncPromise.cancel();
                                    promise.isCancel=true
                                }
                                storeState[kkey] = promise;
                            
                                
                                storeState[kkey].then(data => {
                                    store.commit(real, {
                                        kkey: hasArg ? kkey : '',
                                        data
                                    });
                                    storeState[kkey] = null;
                                })
                            }
                        }
                        if (hasArg && !state[real][kkey]) {
                            Vue.set(state[real], kkey, [])
                        }
                        return hasArg ? state[real][kkey] : state[real]
                    }
                }
            }
        }

    });
    return store = new Vuex.Store({
        state: states,
        getters,
        mutations
    })
}